#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<set>

using namespace std;

int maximumBeauty(vector<int>& nums, int k) {
    sort(nums.begin(), nums.end());

    int l = 0, r = 0, n = nums.size();
    int ans = 0;
    while (r < n)
    {
        while (l < r && nums[l] + k < nums[r] - k)    l++;
        ans = max(ans, r - l + 1);
        r++;
    }
    return ans;
}

int longestConsecutive(vector<int>& nums) {
    set<int> s;
    for (int i = 0; i < nums.size(); i++)  s.insert(nums[i]);

    int ans = 0, last = INT_MIN, cnt = 0;
    for (auto it : s)
    {
        if (last + 1 == it)  cnt++;
        else
        {
            ans = max(ans, cnt);
            cnt = 1;
        }
        last = it;
    }
    ans = max(ans, cnt);
    return ans;
}

int main()
{
    vector<int> nums = { 0,3,7,2,5,8,4,6,0,1 };
    longestConsecutive(nums);
    return 0;
}